import {GetEnterpriseList,GetAlarmsList,GetList } from "@/service/index.js";
import $store from '@/store/index.js'
import { ref } from 'vue'

//当前报警处置点击企业名称时,弹出的框的当前报警界面配置
export const enterpriseNameAlarmCurrent = ref({ //
    detailPropList:[//表格的列信息
        { prop: 'time', label: '报警时间', minWidth: '100',timeStampFormat:"YYYY-MM-DD HH:mm:ss" },
        { prop: 'enterprisename', label: '所属企业', minWidth: '100' },
        { prop: 'type', label: '报警类型', minWidth: '100' },
        { prop: 'instrument', label: '报警点位', minWidth: '100' },
        { prop: 'alarmlevel', label: '报警等级', minWidth: '100'},
        { prop: 'parkname', label: '所属园区', minWidth: '100'},
        { prop: 'districtname', label: '所属区县', minWidth: '100'},
        { prop: 'handler',label: '操作', minWidth: '100'},
    ],
    showSearch:true,//是否显示搜索区域
    searchConfig:{//搜索区域配置
        labelWidth: '100px',
        itemStyle: {
            padding: '10px'
        },
        colLayout: {
            span: 7
        },
        searchProps: [
            {
                field: 'type',
                type: 'select',
                label: '报警事项',
                placeholder: '请选择报警事项',
                options: async()=>{
                    const res = await GetList('analysismodel',{})
                    if(res.code==200){
                        let result = res.data?.map(item=>{
                            return {
                                title:item.model,
                                value:item.model
                            }
                        })
                        return result??[]
                    }else{
                        return []
                    }
                },
                otherOptions: {
                    filterable:true,
                },
            },
            {
                field: 'alarmtime',
                type: 'datepicker',
                label: '报警时间',
                otherOptions: {
                  startPlaceholder: '开始时间',
                  endPlaceholder: '结束时间',
                  type: 'datetimerange',
                  format:"YYYY-MM-DD HH:mm:ss",
                  valueFormat:"YYYY-MM-DD HH:mm:ss"
                }
            }
        ]
    },
    getTableDataFunction:(pagenum,pagesize,queryInfo)=>{//数据初始化方法
        let params = {...queryInfo,pageIndex:pagenum,pageSize:pagesize}//重新定义page，改成接口需要的
        if(Array.isArray(params.alarmtime) && params.alarmtime.length>0){
            let start = params.alarmtime[0]
            let endtime = params.alarmtime[1]
            params.begintime = start
            params.endtime = endtime
        }
        return new Promise((resolve)=>{
            GetAlarmsList(params)
            .then(res=>{
                if (res.data && res.code == "200") {
                    const querysuccess = true;
                    const totalcount = res.total;
                    const datalist = res.data;
                    resolve({querysuccess,totalcount,datalist})
                }else{
                    const querysuccess = false;
                    const totalcount = 0;
                    const datalist = [];
                    resolve({querysuccess,totalcount,datalist})
                }
            })
        })
    }
})



////当前报警处置点击企业名称时,弹出的框的历史报警界面配置
export const enterpriseNameAlarmHistory = ref({
    detailPropList:[//表格的列信息
        { prop: 'time', label: '报警时间', minWidth: '100',timeStampFormat:"YYYY-MM-DD HH:mm:ss" },
        { prop: 'enterprisename', label: '所属企业', minWidth: '100' },
        { prop: 'type', label: '报警类型', minWidth: '100' },
        { prop: 'instrument', label: '报警点位', minWidth: '100'},
        { prop: 'alarmlevel', label: '报警等级', minWidth: '100'},
        { prop: 'parkname', label: '所属园区', minWidth: '100'},
        { prop: 'districtname', label: '所属区县', minWidth: '100'},
        { prop: 'handler',label: '操作', minWidth: '100'},
    ],
    showSearch:true,//是否显示搜索区域
    searchConfig:{//搜索区域配置
        labelWidth: '100px',
        itemStyle: {
            padding: '10px'
        },
        colLayout: {
            span: 7
        },
        searchProps: [
            {
                field: 'type',
                type: 'select',
                label: '报警事项',
                placeholder: '请选择报警事项',
                options: async()=>{
                    const res = await GetList('analysismodel',{})
                    if(res.code==200){
                        let result = res.data?.map(item=>{
                            return {
                                title:item.model,
                                value:item.model
                            }
                        })
                        return result??[]
                    }else{
                        return []
                    }
                },
                otherOptions: {
                    filterable:true,
                },
            },
            {
                field: 'alarmtime',
                type: 'datepicker',
                label: '报警时间',
                otherOptions: {
                  startPlaceholder: '开始时间',
                  endPlaceholder: '结束时间',
                  type: 'datetimerange',
                  format:"YYYY-MM-DD HH:mm:ss",
                  valueFormat:"YYYY-MM-DD HH:mm:ss"
                }
            }
        ]
    },
    getTableDataFunction:(pagenum,pagesize,queryInfo)=>{//数据初始化方法
        let params = {...queryInfo,pageIndex:pagenum,pageSize:pagesize}//重新定义page，改成接口需要的
        if(Array.isArray(params.alarmtime) && params.alarmtime.length>0){
            let start = params.alarmtime[0]
            let endtime = params.alarmtime[1]
            params.begintime = start
            params.endtime = endtime
        }
        return new Promise((resolve)=>{
            GetAlarmsList(params)
            .then(res=>{
                if (res.data && res.code == "200") {
                    const querysuccess = true;
                    const totalcount = res.total;
                    const datalist = res.data;
                    resolve({querysuccess,totalcount,datalist})
                }else{
                    const querysuccess = false;
                    const totalcount = 0;
                    const datalist = [];
                    resolve({querysuccess,totalcount,datalist})
                }
            })
        })
    }
})